#include <57header.h>

// 客户端
int main(int argc,char*argv[])
{
    char *port = "8080";
    char *ip = "192.168.106.129";

    int socket_fd = socket(AF_INET, SOCK_DGRAM,  0);


    struct sockaddr_in sockaddr;
    sockaddr.sin_family = AF_INET;
    sockaddr.sin_port = htons(atoi(port));
    sockaddr.sin_addr.s_addr = inet_addr(ip);

    fd_set set;
    FD_ZERO(&set);
    while(1){
        FD_SET(STDIN_FILENO, &set);
        FD_SET(socket_fd, &set);

        select(10, &set, NULL, NULL, NULL);

        if(FD_ISSET(STDIN_FILENO, &set)){
            char buf[60] = {0};
            read(STDIN_FILENO, buf, sizeof(buf));
            sendto(socket_fd,buf,sizeof(buf),0,(struct sockaddr *)&sockaddr,sizeof(sockaddr));
        }
        if(FD_ISSET(socket_fd, &set)){
            socklen_t len = sizeof(sockaddr);
            char buf[60] = {0};
            recvfrom(socket_fd, buf, sizeof(buf), 0,(struct sockaddr *)&sockaddr, &len);
            printf("buf: %s \n", buf);
        }
    }


    close(socket_fd);
    return 0;
}

